#ifndef __STM32_SPI_H__
#define __STM32_SPI_H__	 

#include <stdio.h>
#include <string.h>
/* SPI外设初始化由STM32CubeMX生成spi.c完成，使用时需包含其头文件spi.h */
#include "spi.h"
#include "bsp_spi.h"

/* 使用的SPI */
#define STM32_SPI1_ENABLE      0
#define STM32_SPI2_ENABLE      0
#define STM32_SPI3_ENABLE      0
#define STM32_SPI4_ENABLE      1
#define STM32_SPI5_ENABLE      0
#define STM32_SPI6_ENABLE      0

#define STM32_SPI_TIMEOUT  10      // 单位ms
#define SPI_MODE_0  0
#define SPI_MODE_1  1
#define SPI_MODE_2  2
#define SPI_MODE_3  3

/* DMA传输完成标志 */
typedef struct __SPI_DMA_Flag_typedef
{
  uint8_t SPI1_Transfer_Complete_Flag;
  uint8_t SPI2_Transfer_Complete_Flag;
  uint8_t SPI3_Transfer_Complete_Flag;
  uint8_t SPI4_Transfer_Complete_Flag;
  uint8_t SPI5_Transfer_Complete_Flag;
  uint8_t SPI6_Transfer_Complete_Flag;
} SPI_DMA_Flag_typedef;

int32_t STM32_SPI_Init(SPI_TypeDef *SPI, SPI_HandleTypeDef *hspi, uint8_t Mode);
int32_t STM32_SPI_TransferData(SPI_HandleTypeDef *hspi, uint8_t *TxData, uint8_t *RxData, uint16_t Length);
int32_t STM32_SPI_TransferData_DMA(SPI_HandleTypeDef *hspi, uint8_t *TxData, uint8_t *RxData, uint16_t Length);
int32_t STM32_SPI_SetSpeed(SPI_HandleTypeDef *hspi, uint32_t SPI_BaudRatePrescaler);



#if (STM32_SPI1_ENABLE == 1)
extern bsp_spi_t BSP_SPI1;
#endif

#if (STM32_SPI2_ENABLE == 1)
extern bsp_spi_t BSP_SPI2;
#endif

#if (STM32_SPI3_ENABLE == 1)
extern bsp_spi_t BSP_SPI3;
#endif

#if (STM32_SPI4_ENABLE == 1)
extern bsp_spi_t BSP_SPI4;
#endif

#if (STM32_SPI5_ENABLE == 1)
extern bsp_spi_t BSP_SPI5;
#endif

#if (STM32_SPI6_ENABLE == 1)
extern bsp_spi_t BSP_SPI6;
#endif


#endif


